package com.cloud.base.queue;


import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class BlockingQueueMain {
    private static BlockingQueue<String> linkedBlockingQueue = new LinkedBlockingQueue<String>(1024);
    private static BlockingQueue<String> blockingQueue = new ArrayBlockingQueue<String>(1024 * 1024);

    public static void main(String[] args) {
        BlockingQueueMain.blockingQueue.add("aaa");
        new Thread(() -> {
            while (true) {
                // 当队列没数据，默认会阻塞，防止cpu变高
                // take（） 消费之后会删除队列数据
                String take = null;
                try {
                    take = BlockingQueueMain.blockingQueue.take();
                    System.out.println(take);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
